[[Subject .Subject "[[.Title]]"]]

[[ define "alert" ]]
<tr>
  <td colspan="2" class="value">
    <span class="value-heading">Value:</span> <span class="value-value">[[ .ValueString ]]</span>
  </td>
</tr>
  [[ if gt (len .Annotations.SortedPairs) 0 ]]
      <tr>
        <td colspan="2" class="annotations">
          [[ range .Annotations.SortedPairs ]]
          <p><span class="annotations-heading">[[ .Name ]]:</span> <span class="annotations-value">[[ .Value ]]</span></p>
          [[ end ]]
        </td>
      </tr>
  [[ end ]]
  <tr>
    <td colspan="2">
      <span class="labels-heading">Labels:</span>
      <ul class="labels-list">
        [[ range .Labels.SortedPairs ]]<li>[[ .Name ]]: [[ .Value ]]</li>[[ end ]]
      </ul>
    </td>
  </tr>
  <tr>
    <td colspan="2" class="actions">
      [[ if .SilenceURL ]]
        <a
          href="[[ .SilenceURL ]]"
          class="button"
        >
          <img
            alt=""
            height="14"
            src=""
            class="button-img"
            width="14"
          />
          Silence
        </a>
      [[ end ]]
      [[ if .Annotations.runbook_url ]]
        <a
          href="[[ .Annotations.runbook_url ]]"
          class="button"
        >
          <img
            class="button-img"
            alt=""
            height="14"
            src=""
            width="14"
          />
          View Runbook
        </a>
      [[ end ]]
      [[ if .DashboardURL]]
        <a
          href="[[ .DashboardURL ]]"
          class="button"
        >
          <img
            alt=""
            height="14"
            class="button-img"
            src=""
            width="14"
          />
          Go to Dashboard
        </a>
      [[ end ]]
      [[ if .PanelURL]]
        <a
          href="[[ .PanelURL ]]"
          class="button"
        >
          <img
            alt=""
            class="button-img"
            height="14"
            src=""
            width="14"
          />
            Go to Panel
          </a>
      [[ end ]]
      [[ if gt (len .GeneratorURL) 0 ]]<a href="[[ .GeneratorURL ]]" class="button">Source</a>[[ end ]]
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <div style="height: 24px"></div>
      <div style="background: #c7d0d9; height: 1px"></div>
      <div style="height: 24px"></div>
    </td>
  </tr>
[[ end ]]

[[ if gt (len .Message) 0 ]]
 [[ .Message ]]
[[ else ]]

<style>
  .button {
    background: #f1f5f9;
    border: 1px solid #c7d0d9;
    border-radius: 2px;
    color: #464c54;
    display: inline-block;
    font-size: 12px;
    font-weight: bold;
    margin: 0 10px 0 0;
    padding: 5px 9px;
  }
  .value {
    font-size: 14px;
    padding-top: 24px;
  }
  .value-heading {
    font-weight: bold;
  }
  .value-value {
    padding-left: 8px;
  }
  .annotations {
    font-size: 14px;
    padding: 24px 0 12px 0;
  }
  .labels-heading {
    font-size: 14px;
    font-weight: bold;
    vertical-align: top;
    display: inline-block;
  }
  .annotations-heading {
    font-weight: bold;
    text-transform: capitalize;
  }
  .annotations-value {
    padding-left: 8px;
  }
  .labels-list {
    font-size: 14px;
    vertical-align: top;
    margin: 0;
    display: inline-block;
    padding-left: 8px;
  }
  .actions {
    padding: 24px 0 12px 0;
  }
  .section-heading {
    color: #2c3235;
    font-size: 22px;
    font-weight: bold;
    padding: 0 0 32px 0;
  }
  .alert-label {
    font-size: 16px;
    font-weight: bold;
    padding: 0 0 0 12px;
    text-decoration: underline;
    vertical-align: middle;
  }
  .status-tag {
    color: #ffffff;
    padding: 4px 8px;
    text-align: center;
    width: 68px
  }
  .status-firing {
    background: #e02f44;
  }
  .status-resolved {
    background: #464c54;
  }
  .button-img {
    height: 14px;
    margin: 0 5px 0 0;
    vertical-align: sub;
    width: 14px;
  }
</style>

<table class="row">
  <tr>
    <td class="twelve">
      <table>
      [[ if gt (len .Alerts.Firing) 0 ]]
        <tr>
          <td colspan="2" class="section-heading">
            Firing: [[ .Alerts.Firing | len ]] alert[[ if gt (len .Alerts.Firing) 1 ]]s[[ end ]][[ if gt (len .GroupLabels.SortedPairs) 1 ]] for
            [[ range .GroupLabels.SortedPairs ]]
            [[ .Name ]]=[[ .Value ]]
            [[ end ]][[ end ]]
          </td>
        </tr>
        [[ range .Alerts.Firing ]]
          <tr>
            <td
              class="status-tag status-firing"
              width="68"
            >
              Firing
            </td>
            <td class="alert-label">
              [[ .Labels.alertname ]]
            </td>
          </tr>
          [[ template "alert" . ]]
        [[ end ]]
      [[ end ]]
      [[ if gt (len .Alerts.Resolved) 0 ]]
        <tr>
          <td colspan="2" class="section-heading">
            Resolved: [[ .Alerts.Resolved | len ]] alert[[ if gt (len .Alerts.Resolved) 1 ]]s[[ end ]][[ if gt (len .GroupLabels.SortedPairs) 1 ]] for
            [[ range .GroupLabels.SortedPairs ]]
            [[ .Name ]]=[[ .Value ]]
            [[ end ]][[ end ]]
          </td>
        </tr>
        [[ range .Alerts.Resolved ]]
          <tr>
            <td
              class="status-tag status-resolved"
              width="68"
            >
              Resolved
            </td>
            <td class="alert-label">
              [[ .Labels.alertname ]]
            </td>
          </tr>
          [[ template "alert" . ]]
        [[ end ]]
      [[ end ]]
      <tr>
        <td colspan="2">
          <a href="[[ .AlertPageUrl ]]" class="button">Go to alerts page</a>
        </td>
      </tr>
      </table>
      </table>
    </td>
  </tr>
</table>
[[ end ]]
